import request from '@/utils/request'
import { HTTP_METHOD } from '@/utils/http'

const BASE_URL = '/group'

/**
 * @export 添加群组
 * @param {*} data
 * @return {*}
 */
export function addGroup (data) {
  return request({
    url: BASE_URL,
    method: HTTP_METHOD.POST,
    data,
  })
}

/**
 * @export 获取群组列表
 */
export function getGroups (per_page, page, params) {
  return request({
    url: BASE_URL,
    method: HTTP_METHOD.GET,
    params: {
      per_page,
      page,
      ...params,
    },
  })
}

/**
 * @export 获取群组信息
 * @param {*} gid
 * @return {*}
 */
export function getGroup (gid) {
  return request({
    url: `${BASE_URL}/${gid}`,
    method: HTTP_METHOD.GET,
  })
}

/**
 * @export 修改群组信息
 * @param {*} data
 * @return {*}
 */
export function modifyGroup (data) {
  return request({
    url: `${BASE_URL}`,
    method: HTTP_METHOD.PUT,
    data,
  })
}

/**
 * @export 获取群组人员
 * @param {*} per_page
 * @param {*} page
 * @param {*} data
 * @return {*}
 */
export function getGroupUsers (per_page, page, data) {
  return request({
    url: `${BASE_URL}/user/${data.gid}`,
    method: HTTP_METHOD.GET,
    params: { per_page, page },
  })
}

/**
 * @export 删除群组
 * @param {*} gid
 */
 export function deleleGroup (gid) {
  return request({
    url: `${BASE_URL}/${gid}`,
    method: HTTP_METHOD.DELETE,
  })
}

/**
 * @export 改变群组状态
 * @param {*} gid
 */
export function changeActive (gid) {
  return request({
    url: `${BASE_URL}/${gid}`,
    method: HTTP_METHOD.PUT,
  })
}

/**
 * @export 群组添加人员
 * @param {*} gid id
 * @param {*} data
 * @return {*}
 */
export function addGroupUsers (gid, data) {
  return request({
    url: `${BASE_URL}/user/${gid}`,
    method: HTTP_METHOD.POST,
    data,
  })
}

/**
 * @export 删除群组人员
 * @param {*} gid id
 * @param {*} data
 * @return {*}
 */
export function deleteGroupUsers (gid, data) {
  return request({
    url: `${BASE_URL}/user/${gid}`,
    method: HTTP_METHOD.DELETE,
    data,
  })
}

/**
 * @export 获取群组权限
 * @param {*} gid
 * @return {*}
 */
export function getGroupAuths (gid) {
  return request({
    url: `${BASE_URL}/auth/${gid}`,
    method: HTTP_METHOD.GET,
  })
}

/**
 * @export 修改群组权限
 * @param {*} gid id
 * @param {*} data
 * @return {*}
 */
export function modifyGroupAuths (gid, data) {
  return request({
    url: `${BASE_URL}/auth/${gid}`,
    method: HTTP_METHOD.PUT,
    data,
  })
}
